# Maintainer: Lucio Perusini <lucioperusini@gmail.com>
# Contributor: R4SAS <r4sas@i2pmail.org>

_realname=i2pd
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=2.45.1
pkgrel=2
pkgdesc='A full-featured C++ implementation of the I2P router (mingw-w64)'
url='https://i2pd.website/'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-miniupnpc"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/PurpleI2P/i2pd/archive/${pkgver}.tar.gz"
        "0001-i2pd-makefile.patch")
sha256sums=('a84b1e3cb5ac45f39af98e63291d34725ef67337e11acbe0e245acde7a5b2b72'
            '5e9f02036dc544dd4695993a8d8dab088d8470b8d3a118d92702e7f8c8f0e4d9')
noextract=("${_realname}-${pkgver}.tar.gz") # symlinks

prepare() {
  tar -xf "${_realname}-${pkgver}.tar.gz" || true
  cd "${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}"/0001-i2pd-makefile.patch
}

build() {
  cp -rf "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "${srcdir}"/build-${MSYSTEM}

  make USE_UPNP=yes
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  #bin
  install -d "${pkgdir}${MINGW_PREFIX}/bin/"
  cp i2pd.exe "${pkgdir}${MINGW_PREFIX}/bin/"

  #config
  install -d "${pkgdir}${MINGW_PREFIX}/etc/i2pd"
  cp contrib/{i2pd,tunnels}.conf "${pkgdir}${MINGW_PREFIX}/etc/i2pd"
  install -d "${pkgdir}${MINGW_PREFIX}/etc/i2pd/tunnels.d"
  cp contrib/tunnels.d/{*.conf,README} "${pkgdir}${MINGW_PREFIX}/etc/i2pd/tunnels.d"

  # certificates
  install -d "${pkgdir}${MINGW_PREFIX}/share/i2pd"
  cp -r contrib/certificates "${pkgdir}${MINGW_PREFIX}/share/i2pd"

  # license
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
